home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / polyCheckSelection.mel < prev    next >
Encoding:
Text File  |  2003-07-17  |  4.7 KB  |  153 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. //
  18. //  Alias|Wavefront Script File
  19. //  MODIFY THIS AT YOUR OWN RISK
  20. //
  21. //  Creation Date:  18 April 1997
  22. //
  23. //
  24.  
  25.  
  26. proc concatArray (string $res[], string $in[])
  27. {
  28.     for ($i in $in)
  29.         $res[size($res)] = $i;
  30. }
  31.  
  32. proc string[] extractShapesWithPath (string $in[], string $type)
  33. {
  34.     string $res[];    
  35.     for ($i in $in) {
  36.         // first test that the visibility exists for the object
  37.  
  38.         string $vis_exists[1]=`listAttr -s -st visibility $i`;
  39.         if (size($vis_exists) == 0) continue;
  40.         // then check if the object is visible (or it will mess up the
  41.         // unite/separate implementation)
  42.         int $vis=`getAttr ($i + ".visibility")`;
  43.         if ($vis != 1) continue;
  44.         
  45.         // now check if the object is not an intermediate object...
  46.         $vis_exists=`listAttr -s -st intermediateObject $i`;
  47.         if (size($vis_exists) != 0) {
  48.             $vis=`getAttr ($i + ".intermediateObject")`;
  49.             if ($vis != 0) continue;
  50.         }
  51.         
  52.         if ($type == `nodeType $i`) $res[size($res)]=$i;
  53.         else {
  54.             // this means that if a top level object is selected
  55.             // its children are selected too...
  56.             string $curlevel[]=`listRelatives -c -pa $i`;
  57.             if (size($curlevel) != 0)
  58.                 concatArray $res `extractShapesWithPath $curlevel $type`; 
  59.         }
  60.     }
  61.     return $res;
  62. }
  63.  
  64. global proc string[] polyCheckSelection (string $fun, string $funtype)
  65. {
  66. // first set up various attributes & selection constraints
  67. // to allow the action to show up clearly
  68.  
  69. // extract command name
  70.     string $tmp[];
  71.     tokenize($fun, $tmp);
  72.     $fun = $tmp[0];
  73.     
  74.     string $sres[];
  75.     int $res=0;
  76.     int $isInstalled=0;
  77.     
  78.     if ($funtype == "o") { 
  79.         // for function that work on objects, we need to do the job ourselves...
  80.         string $sel[];
  81.         polyInstallAction -uc -ud; // remove any pending constraint.
  82.  
  83.         // unite, separate and boolean ops want all the shapes, 
  84.         // but with their correct path information.            
  85.         // Note bool ops need to take the lead object separately...
  86.         $sel=`ls -sl`;
  87.         string $hllist[]=`ls -hl`;
  88.         if (size($hllist) != 0)
  89.             concatArray $sel $hllist;
  90.         $sres=`extractShapesWithPath $sel "mesh"`;
  91.         $res=size($sres);
  92.  
  93.         clear $sel;
  94.         if ($res == 0)
  95.             warning ($fun + " works only on polygonal objects.");
  96.     } else {
  97.         if (`optionVar -q polyAutoConvertAction`)
  98.         {
  99.             $sres = `polyInstallAction -cs $fun`;
  100.              if (! `optionVar -q polyAutoInstallAction`)
  101.                  polyInstallAction; // Remove settings
  102.         }
  103.         else if (`optionVar -q polyAutoInstallAction`)
  104.             $sres = `polyInstallAction $fun`;
  105.         else
  106.         {
  107.             polyInstallAction;                // Remove prev settings
  108.             $sres = `ls -sl`;
  109.         }
  110.         // usually polyInstallAction of a poly command provides
  111.         // the list of all matching items
  112.         $res = size($sres);
  113.         $isInstalled = `polyInstallAction -q -cn` != "";        
  114.     }
  115.  
  116.     global string $polyLastTool;
  117.     global string $gSelect;
  118.  
  119.     if ($res == 0) {
  120.         if (! `optionVar -q polyAutoInstallAction`) {
  121.             if ($isInstalled)
  122.                 polyInstallAction -uc $fun;
  123.             // no last tool to store    
  124.             $polyLastTool="";
  125.         } else {
  126.             // *** should show in setSelectMode that the mode is for $fun
  127.             // *** should set a script job to remove the sel. constraints.
  128.             // when the selectMode or selectType is changed.
  129.             $polyLastTool=`currentCtx`;
  130.             setToolTo $gSelect;
  131.         }
  132.     } else {
  133.         if (`optionVar -q polyAutoInstallAction` &&
  134.                     (`getModifiers` % 2) == 1) { // shift is down
  135.             warning ("Setup for " + $fun);
  136.             // setup for action: don't do the action, just prepare for it...
  137.             clear $sres;
  138.             // *** should show in setSelectMode that the mode is for $fun
  139.             // *** should set a script job to remove the sel. constraints.
  140.             // when the selectMode or selectType is changed.
  141.         } else {
  142.             // uninstall selection constraints
  143.             if ($isInstalled)
  144.                 polyInstallAction -uc $fun;
  145.         }
  146.         // store last tool
  147.         $polyLastTool=`currentCtx`;
  148.         setToolTo $gSelect;
  149.     }
  150. // return array of objs to process
  151.     return $sres;
  152. }
  153.